<template>
  <div>
      <div class="newsTop">
        <el-breadcrumb separator=">>">
          <el-breadcrumb-item :to="{ path: '/' }">主页</el-breadcrumb-item>
          <el-breadcrumb-item>消息通知</el-breadcrumb-item>
        </el-breadcrumb>
        <el-Button class="btn_all_read" @click="readAll()">全部已读</el-Button>
    </div>
      <el-card class="box-card">
        <div v-show="this.newsLists.length===0">暂无消息</div>
        <div v-for="(li,index) in newsLists" :key="index" class="text item ">
         <h4 class="title">{{li.title}}</h4>
         <p class="content">{{li.content}}</p>
          <div class="caozuo">
            <el-Button type="danger" @click='delNews(index)'>删除</el-Button>
            <el-Button type="primary" @click="readNews(index)" :disabled="li.read">{{li.read?"已读":"点击已读"}}</el-Button>
          </div>
        </div>
      </el-card>
  </div>
</template>

<script>
import {mapState,mapMutations} from "vuex"
  export default {
    data(){
      return{}
    },
    methods:{
      delNews(index){
        if(confirm("您确认删除吗?")){
          this.del_news(index)
        }
      },
      //点击已读
      readNews(index){
        this.read_news(index)
      },
      //点击全部已读
      readAll(){
         this.all_read() 
      },
      
      ...mapMutations(["del_news","read_news","all_read"])
    },
    computed:{
      ...mapState(['newsLists'])
    }
  }
</script>

<style lang="scss" scoped>
.newsTop{
  height:60px;
  position:relative;
  background:rgb(252, 249, 249);
  .el-breadcrumb{
    height:60px;
    line-height:60px;
    color:#000;
  }
  .btn_all_read{
    position:absolute;
    right:20px;
    top:10px;
  }

}
 .text {
   position:relative;
    font-size: 14px;
    .title{
      height:30px;
      font-weight:bold;
      line-height:30px;
      text-align: left;
    }
    .content{
      width:1200px;
      line-height:20px;
      text-align:left;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }

  }

  .item {
    padding: 18px 0;
  }

  .box-card {
    width: 100%;
  }

.caozuo{
  position:absolute;
  right:0;
  top:0;
}

</style>